var SetAllSelects2 = {
	Offset:function(e) {
		var t = e.offsetTop;
		var l = e.offsetLeft;
		var w = e.offsetWidth;
		var h = e.offsetHeight;
		while(e = e.offsetParent) { t += e.offsetTop; l += e.offsetLeft; }
		return {top:t, left:l, width:w,	height:h};
	},
	setCreated:function(obj,status) { //设置属性
		obj.setAttribute("childCreated",status);
	},
	getCreated:function(obj) { //获取属性
		var status = obj.getAttribute("childCreated");
		if(status == null) { status = ""; }
		return status;
	}, setSelectStyle2:function(obj, idnum, showHeight) {
		if(obj.id == null || obj.id == "") { obj.id = "selectID_" + idnum; }
		var offset = this.Offset(obj);
		obj.style.display = "none";
		var mainDiv = document.createElement("div");
		var js_select_ = "select2_";
		var _this = this;
		mainDiv.id = "d_" + obj.id
		mainDiv.className = "oDiv input-group-btn";
		mainDiv.style.width = (showHeight + 45) + "px";
		var tValue = "";
		try {
			tValue = obj.options[obj.selectedIndex].innerHTML;
		} catch(e) {
			tValue = "";
		}
		var sValue = "";
		try {
			sValue = obj.options[obj.selectedIndex].value;
		} catch(e) {
			sValue = "";
		}
		var iDiv = document.createElement("div");
		iDiv.className = "iDiv2";
		iDiv.id = js_select_ + obj.id;
		iDiv.style.width = showHeight + "px";
		iDiv.setAttribute("tabindex", "0");
		iDiv.innerHTML = tValue;
		iDiv.setAttribute("title", tValue);
		mainDiv.appendChild(iDiv);
		iDiv.setAttribute("data-toggle", "dropdown");
		iDiv.onclick = function() {
			$(mainDiv).find(".dropdown-menu").getNiceScroll().remove();
			if($(this).parent().find("ul").length == 0) {
				var uUl = document.createElement("ul");
				uUl.className = "dropdown-menu";
				uUl.style.width = (showHeight + 45) + "px";
				mainDiv.appendChild(uUl);
				for (var i = 0; i < obj.options.length; i++) {
					var lLi = document.createElement("li");
					var aInnerLi = document.createElement("a");
					lLi.appendChild(aInnerLi);
					lLi.style.width = (showHeight + 45) + "px";
					if(!obj.selectedIndex && i == obj.selectedIndex) {
						lLi.className = "active";
					}
					aInnerLi.setAttribute("data-value", obj.options[i].value);
					aInnerLi.setAttribute("data-value2", i);
					aInnerLi.setAttribute("href", "javascript:;");
					aInnerLi.innerHTML = obj.options[i].innerHTML;
					var option = obj.options[i];
					aInnerLi.onclick = function() {
						iDiv.innerHTML = this.text;
						iDiv.setAttribute("title", this.text);
						$(obj).get(0).selectedIndex = $(this).data("value2");
						if(!$(this).parent().hasClass("active")) {
							$(this).parent().addClass("active").siblings().removeClass("active");
							if(obj.getAttribute("onchange") != null && obj.getAttribute("onchange") != "") {
								try {
									var nodeValue = obj.getAttribute("onchange");
									eval(nodeValue.substring(0, nodeValue.indexOf("(") + 1) + "document.getElementById('" + obj.id + "'))");
								} catch(e) {
									console.error(obj.getAttribute("onchange") + " is not a function");
								}
							}
						}
						$(mainDiv).removeClass("open");
						$(this).parent().parent().hide();
					}
					uUl.appendChild(lLi);
				}
				$(mainDiv).addClass("open");
			}
			if($(mainDiv).hasClass("open") || !$(mainDiv).find(".dropdown-menu").is(':visible')) {
		        $(mainDiv).removeClass("open");
		        if(!$(mainDiv).find(".dropdown-menu").is(':visible')) {
			        $(mainDiv).find(".dropdown-menu").show();
		        }
	    	} else {
		        $(mainDiv).addClass("open");
	    		$(mainDiv).find("li.active").removeClass("active");
		        $(mainDiv).find(".dropdown-menu").hide();
	    	}
			$(mainDiv).find(".dropdown-menu").niceScroll({styler:"fb",cursorcolor:"#eeeeee", cursorwidth: '14', cursorborderradius: '0px', background: '#ffffff', spacebarenabled:false, cursorborder: '0', horizrailenabled: false});
		}
		$(obj).parent().append(mainDiv);
	},
	setAllSelectStyle2:function(name) {
		try {
			$("#d_" + name).remove();
			var s = document.getElementById(name);
			this.setSelectStyle2(s,0, 135);
		} catch(e){
		}
	}
}
document.onclick = function(e) {
	e = e || window.event;
	var target = e.target || event.srcElement;
	$("[id^=d_]").each(function(){
		var objdivtmp = document.getElementById($(this).attr("id"));
		if ($(this).find("ul").is(":visible")) {
			var id2 = $(this).attr("id").split("_")[1];
			if(target.id.indexOf(id2) <= 0 || objdivtmp.id.indexOf(id2) <= 0) {
		        $(this).find(".dropdown-menu").hide();
			}
		}
	});
}
